﻿var Master = {}

Master._height = null;

/// <summary>Initialize the Master view.</summary>
Master.init = function () {
    // Initialize the main splitter.
    $("#mainSplitter").kendoSplitter({
        orientation: "vertical",
        panes: [
            { size: "104px", resizable: false }
        ]
    });

    $("#mainMenu").kendoMenu({
        dataSource: [{
            text: "Home",
            url: "http://www.telerikmvpsamples.com"
        }]
    });

    // Initialize the content splitter.
    $("#contentSplitter").kendoSplitter({
        panes: [
            { size: "200px", collapsible: true }
        ]
    });
    $('#navigationPane').load(_rootUrl + "Views/Navigation.aspx");

    // Hide th e scrollbar in the main splitter.
    $('#mainSplitter').children('div.k-pane').css('overflow-y', 'hidden');

    // Call the Master.resize function every 100 miliseconds.
    setInterval("Master.resize()", 100);
}

/// <summary>Check the size of the window, and if it has changed, then resize the splitters to fit the window.</summary>
Master.resize = function () {
    var height = $(window).height();

    // Has the window height changed?
    if (height != Master._height) {
        Master._height = height;

        // Resize the main splitter.
        var mainSplitter = $('#mainSplitter');
        mainSplitter.height(height - 25);
        mainSplitter.resize();

        // Resize the content splitter.
        var contentSplitter = $('#contentSplitter');
        contentSplitter.height(height - 77);
        contentSplitter.resize();
    }
}


Master.Navigation = {}

Master.Navigation.init = function () {
    $("#navPanelBar").kendoPanelBar({
        expandMode: "single",
        select: Master.Navigation.navPanelBar_onSelect
    });
}

Master.Navigation.navPanelBar_onSelect = function (e) {
    if ($(e.item).hasClass("tm-sprint")) {
        $("#contentPane").load(_rootUrl + "Views/Sprint.aspx?id=" + $(e.item).attr("id"));
    } else if ($(e.item).hasClass("tm-developer")) {
        $("#contentPane").load(_rootUrl + "Views/Developer.aspx?id=" + $(e.item).attr("id"));
    }
}

Master.Navigation.syncNavPanelBar = function (funcptr) {
    $('#navigationPane').load(_rootUrl + "Views/Navigation.aspx", funcptr);
}

Master.Navigation.expandDeveloperItem = function () {
    var panelBar = $("#navPanelBar").data("kendoPanelBar");
    panelBar.expand(panelBar.element.find("li.tm-developer-pane"));
}